package seqList;

import java.util.Arrays;

public class Seqlist {
    private int[] arr;
    private int size;
    private static final int DEFUCT_SIZE=2;

    public Seqlist(int i) {
        this.arr=new int[i];
    }

    public Seqlist() {
        this.arr=new int[DEFUCT_SIZE];
    }

    public void show(){
        for (int i = 0; i < size; i++) {
            System.out.println(arr[i]);
        }
    }

    public void add(int val){
        boolean isfull = isFull(arr);
        if(isfull){
            this.arr= Arrays.copyOf(arr, arr.length * 2);
        }
            this.arr[this.size]=val;
            this.size++;
    }
    //在指定位置插入元素
    public void add(int pos,int val){
        if(pos<0||pos>this.size){
            throw new PosOutOfBoundException(pos+"位置不合法");
//            System.out.println("位置不合法");
//            return;
        }
        if(isFull(arr)){
            this.arr= Arrays.copyOf(arr, arr.length * 2);
        }
        for (int i = this.size-1; i >= pos; i--) {
            arr[i+1]=arr[i];
        }
        arr[pos]=val;
        this.size++;
    }

    public boolean contains(int val){
        for (int i = 0; i < this.size; i++) {
            if(arr[i]==val){
                return true;
            }
        }
        return false;
    }

    public boolean isFull (int[] arr){
        if(arr.length==this.size){
            return true;
        }
        else{
            return false;
        }
    }
}
